import java.util.*;

public class HashDemo {
    public static void main(String[] args) {
        HashMap <String,String> hp = new HashMap  <String,String> ();
        hp.put("1","milk1");
        hp.put("2","milk2");
        hp.put("3","milk3");
        hp.put("4","milk4");

        System.out.println(hp);
        System.out.println(hp.keySet());//获取key集合-》 set类型
        System.out.println(hp.values());

        //如何获取key值
        Set <String> keySet = hp.keySet();
        Iterator<String> it = keySet.iterator();
        while(it.hasNext()){
            String key = it.next();
            String value = hp.get(key);//通过key找value
            System.out.println(key+":"+value);

            hp.forEach((key,value)->System.out.println(key));  //foreach遍历 -》a表达式
        }
    }
}
